<template>
  <view v-if="shenheStatus == 0" class="cash">
    <!-- 提现输入框 -->
    <view class="input-box">
      <view class="input-title">{{ $t('user.trans') }}</view>
      <view class="input">
        <view>￥</view>
        <view>
          <u-input v-model="inputNum" placeholder=" "></u-input>
        </view>
      </view>
    </view>

    <!-- 全部提现 -->
    <view class="all-withdrawal">
      {{ $t('user.canTrans') }}{{ myInfo.user_info.money
      }}{{ $t('order.integral3') }}，
      <text
        @click="inputNum = myInfo.user_info.money"
        style="color: #f0250e; font-weight: 600"
        >{{ $t('user.allTrans') }}</text
      >
    </view>

    <!-- 提交button -->
    <view @click="submit" class="btn flex-y-center flex-x-center">{{
      $t('user.toTrans')
    }}</view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from '@/components/shenhe/shenhe';
export default {
  components: {
    Shenhe,
  },
  data() {
    return {
      inputNum: '', //输入提现金额
      showPopup: false, //popup弹框开关
      myInfo: {}, //提现所有数据
    };
  },
  onShow() {
    this.getCashInfo();
  },
  methods: {
    // 获取提现数据
    async getCashInfo() {
      try {
        const res = await this.$allrequest.request.userindex({});
        if (res.code != 0) throw res;
        this.myInfo = res.data;
      } catch (error) {
        this.$utils.toast(error.msg || this.$t('user.err'));
      }
    },
    submit() {
      // 正则,最多两位小数
      var t = /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/;
      if (!t.test(this.inputNum)) {
        this.inputNum = '';
        return this.$utils.toast(this.$t('user.errMoney'));
      }

      if (this.inputNum - 0 > this.myInfo.user_info - 0) {
        this.inputNum = '';
        return this.$utils.toast(this.$t('user.noMore'));
      }

      uni.showModal({
        title: this.$t('user.tip'),
        content: `${this.$t('user.tip1')}${this.inputNum}${this.$t(
          'user.tip2'
        )}?`,
        success: async res => {
          if (res.confirm) {
            const res = await this.$allrequest.user.switchBonus(
              {
                price: this.inputNum,
              },
              true
            );
            if (res.code != 0) return this.$utils.toast(res.msg);
            this.$utils.toast(res.msg);
            this.inputNum = this.$options.data().inputNum;
            this.getCashInfo();
          } else if (res.cancel) {
          }
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.cash {
  color: #262626;
  font-family: PingFang SC;
  padding: 0 36rpx;
}
.way {
  height: 102rpx;
  border-bottom: 2rpx solid #f1f1f1;
  > view:nth-child(1) {
    height: 42rpx;
    font-size: 30rpx;
    font-weight: 600;
  }
  > view:nth-child(2) {
    height: 40rpx;
    font-size: 28rpx;
    .iconfont {
      font-size: 44rpx;
      &:nth-child(1) {
        margin-right: 10rpx;
      }
    }
    > text:nth-child(2) {
      margin-top: -2rpx;
    }
  }
}
.input-box {
  .input-title {
    padding: 30rpx 0;
    line-height: 42rpx;
    font-size: 30rpx;
    font-weight: 600;
  }
  .input {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f1f1f1;
    padding-bottom: 20rpx;
    > view:nth-child(1) {
      font-size: 40rpx;
      font-weight: 600;
      transform: translateY(8rpx);
    }
    > view:nth-child(2) {
      flex: 1;
      width: 0;
      /deep/.u-input__input {
        font-size: 56rpx;
        font-weight: 600;
        height: 112rpx;
        color: #262626;
      }
    }
  }
}

.all-withdrawal {
  margin-top: 28rpx;
  margin-bottom: 80rpx;
  height: 34rpx;
  font-size: 24rpx;
  color: #8c8c8c;
}

.btn {
  width: 678rpx;
  height: 88rpx;
  background: #f0250e;
  opacity: 1;
  border-radius: 120rpx;
  font-size: 32rpx;
  font-weight: 500;
  color: #ffffff;
}

.popup-box {
  width: 600rpx;
  padding: 0 50rpx;
  color: #262626;
  .title {
    height: 90rpx;
    line-height: 90rpx;
    font-size: 32rpx;
    font-weight: 600;
    text-align: center;
  }
  .popup-item {
    height: 100rpx;
    border-bottom: 1px solid #f1f1f1;
    font-size: 28rpx;
    .iconfont {
      font-size: 50rpx;
      margin-right: 15rpx;
    }
  }
}
</style>
